package cn.taketoday.live.tools;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.taketoday.live.config.CenterSetConfig;
import cn.taketoday.live.config.GlobalData;
import cn.taketoday.live.data.enums.AdvertStatus;
import cn.taketoday.live.data.enums.ShieldGift;
import cn.taketoday.live.data.enums.ShieldMessage;
import cn.taketoday.live.data.enums.ThankGiftStatus;

/**
 * @author BanqiJane
 */
public class ParseSetStatusTools {
  public static ShieldGift getGiftShieldStatus(short code) {
    switch (code) {
      case 0:
        return ShieldGift.OPTIONAL;
      case 1:
        return ShieldGift.SILVER;
      case 2:
        return ShieldGift.HIGH_PRICE;
      case 3:
        return ShieldGift.CUSTOM_RULE;
      default:
        return ShieldGift.OPTIONAL;
    }
  }

  public static ThankGiftStatus getThankGiftStatus(short code) {
    switch (code) {
      case 0:
        return ThankGiftStatus.one_people;
      case 1:
        return ThankGiftStatus.some_people;
      case 2:
        return ThankGiftStatus.some_peoples;
      default:
        return ThankGiftStatus.one_people;
    }
  }

  public static AdvertStatus getAdvertStatus(short code) {
    switch (code) {
      case 0:
        return AdvertStatus.DEFAULT;
      case 1:
        return AdvertStatus.RANDOM;
      default:
        return AdvertStatus.DEFAULT;
    }
  }

  public static Map<ShieldMessage, Boolean> getMessageMap(CenterSetConfig centerSetConf, short live_status) {
    Map<ShieldMessage, Boolean> map = new ConcurrentHashMap<>(18);
    if (centerSetConf.isIs_barrage_guard()) {
      map.put(ShieldMessage.is_barrage_guard, true);
    }
    else {
      map.put(ShieldMessage.is_barrage_guard, false);
    }
    if (centerSetConf.isIs_cmd()) {
      map.put(ShieldMessage.is_cmd, true);
    }
    else {
      map.put(ShieldMessage.is_cmd, false);
    }
    if (centerSetConf.isIs_barrage_vip()) {
      map.put(ShieldMessage.is_barrage_vip, true);
    }
    else {
      map.put(ShieldMessage.is_barrage_vip, false);
    }
    if (centerSetConf.isIs_barrage_manager()) {
      map.put(ShieldMessage.is_barrage_manager, true);
    }
    else {
      map.put(ShieldMessage.is_barrage_manager, false);
    }
    if (centerSetConf.isIs_barrage_medal()) {
      map.put(ShieldMessage.is_barrage_medal, true);
    }
    else {
      map.put(ShieldMessage.is_barrage_medal, false);
    }
    if (centerSetConf.isIs_barrage_ul()) {
      map.put(ShieldMessage.is_barrage_ul, true);
    }
    else {
      map.put(ShieldMessage.is_barrage_ul, false);
    }
    if (centerSetConf.isIs_block()) {
      map.put(ShieldMessage.is_block, true);
    }
    else {
      map.put(ShieldMessage.is_block, false);
    }
    if (centerSetConf.isIs_follow()) {
      map.put(ShieldMessage.is_follow, true);
    }
    else {
      map.put(ShieldMessage.is_follow, false);
    }
    if (centerSetConf.isIs_gift()) {
      map.put(ShieldMessage.is_gift, true);
    }
    else {
      map.put(ShieldMessage.is_gift, false);
    }
    if (centerSetConf.isIs_welcome()) {
      map.put(ShieldMessage.is_welcome, true);
    }
    else {
      map.put(ShieldMessage.is_welcome, false);
    }
    if (centerSetConf.isIs_welcome_all()) {
      map.put(ShieldMessage.is_welcome_all, true);
    }
    else {
      map.put(ShieldMessage.is_welcome_all, false);
    }
    if (!StringUtils.isEmpty(GlobalData.USERCOOKIE)) {
      //礼物码模式
      if (centerSetConf.getThank_gift().isIs_gift_code()) {
        map.put(ShieldMessage.is_giftCode, true);
      }
      else {
        map.put(ShieldMessage.is_giftCode, false);
      }
      //天选屏蔽
      if (centerSetConf.getThank_gift().isIs_tx_shield()) {
        map.put(ShieldMessage.is_giftShield, true);
      }
      else {
        map.put(ShieldMessage.is_giftShield, false);
      }
      if (centerSetConf.getFollow().isIs_tx_shield()) {
        map.put(ShieldMessage.is_followShield, true);
      }
      else {
        map.put(ShieldMessage.is_followShield, false);
      }
      if (centerSetConf.getWelcome().isIs_tx_shield()) {
        map.put(ShieldMessage.is_welcomeShield, true);
      }
      else {
        map.put(ShieldMessage.is_welcomeShield, false);
      }
      //舰长私信
      if (centerSetConf.getThank_gift().isIs_guard_report()) {
        map.put(ShieldMessage.is_guard_report, true);
      }
      else {
        map.put(ShieldMessage.is_guard_report, false);
      }
      //关注
      if (centerSetConf.getFollow().isIs_live_open()) {
        if (live_status != 1) {
          map.put(ShieldMessage.is_followThank, false);
        }
        else {
          if (centerSetConf.getFollow().isIs_open()) {
            map.put(ShieldMessage.is_followThank, true);
          }
          else {
            map.put(ShieldMessage.is_followThank, false);
          }
        }
      }
      else {
        if (centerSetConf.getFollow().isIs_open()) {
          map.put(ShieldMessage.is_followThank, true);
        }
        else {
          map.put(ShieldMessage.is_followThank, false);
        }
      }

      //欢迎感谢
      if (centerSetConf.getWelcome().isIs_live_open()) {
        if (live_status != 1) {
          map.put(ShieldMessage.is_welcomeThank, false);
        }
        else {
          if (centerSetConf.getWelcome().isIs_open()) {
            map.put(ShieldMessage.is_welcomeThank, true);
          }
          else {
            map.put(ShieldMessage.is_welcomeThank, false);
          }
        }
      }
      else {
        if (centerSetConf.getWelcome().isIs_open()) {
          map.put(ShieldMessage.is_welcomeThank, true);
        }
        else {
          map.put(ShieldMessage.is_welcomeThank, false);
        }
      }
      //舰长是否保持在本地
      if (centerSetConf.getThank_gift().isIs_guard_local()) {
        map.put(ShieldMessage.is_guard_local, true);
      }
      else {
        map.put(ShieldMessage.is_guard_local, false);
      }
      //是否感谢礼物
      if (centerSetConf.getThank_gift().isIs_live_open()) {
        if (live_status != 1) {
          map.put(ShieldMessage.is_giftThank, false);
        }
        else {
          if (centerSetConf.getThank_gift().isIs_open()) {
            map.put(ShieldMessage.is_giftThank, true);
          }
          else {
            map.put(ShieldMessage.is_giftThank, false);
          }
        }
      }
      else {
        if (centerSetConf.getThank_gift().isIs_open()) {
          map.put(ShieldMessage.is_giftThank, true);
        }
        else {
          map.put(ShieldMessage.is_giftThank, false);
        }
      }
    }
    else {
      //舰长私信
      map.put(ShieldMessage.is_guard_report, false);
      //关注感谢
      map.put(ShieldMessage.is_followThank, false);
      //舰长本地
      map.put(ShieldMessage.is_guard_local, false);
      //礼物感谢
      map.put(ShieldMessage.is_giftThank, false);
    }

    return map;
  }

}
